package cn.sccl.dirms.sms;

import org.apache.commons.collections.map.ListOrderedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import java.util.Map;

/**
 * 短信信息 生产者
 * Created by xf-cl on 2017/11/22.9:55
 */
@Service
public class ProducerServiceImpl implements ProducerService{
    private static Logger log = LoggerFactory.getLogger(ProducerServiceImpl.class);
    @Autowired
    private JmsTemplate jmsTemplate;

    /**
     * 向mq队列发送信息  生产短信信息
     * @param destination
     * @param map
     */
    @Override
    public void producerSms(Destination destination, final Map<String,Object> map) {
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                log.debug("正在创建activemq格式的消息,向activemq队列中发送该消息：告警id【"+map.get("alertid")+"】");
                return session.createObjectMessage((ListOrderedMap)map);
            }
        });
    }
}
